package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.PlanTunnelRepairReq;
import net.hn.hnms.biz.plan.service.PlanTunnelRepairService;
import net.hn.hnms.biz.plan.vo.PlanTunnelRepairVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "巷道修复计划模块", tags = {"巷道修复计划"})
@RestController
@RequestMapping("/TunnelRepair")
public class PlanTunnelRepairController  extends BaseController {

    @Autowired
    private PlanTunnelRepairService planTunnelRepairService;


    /**
     * 新增巷道修复计划
     */
    @ApiOperation("新增巷道修复计划")
    @SaCheckPermission("plan:PlanTunnelRepair:add")
    @PostMapping("/add")
    @Log(title = "新增巷道修复计划", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody PlanTunnelRepairReq planMining) {
        return toAjax(planTunnelRepairService.insert(planMining));
    }

    /**
     * 删除巷道修复计划
     */
    @ApiOperation("删除巷道修复计划")
    @SaCheckPermission("plan:PlanTunnelRepair:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除巷道修复计划", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        planTunnelRepairService.deleteBatch(idList);
        return R.ok();
    }


    /**
     * 修改巷道修复计划
     */
    @ApiOperation("修改巷道修复计划")
    @SaCheckPermission("plan:PlanTunnelRepair:update")
    @PutMapping("/update")
    @Log(title = "修改巷道修复计划", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody PlanTunnelRepairReq planMining) {
        planTunnelRepairService.updateById(planMining);
        return R.ok();
    }


    /**
     * 启用/禁用
     */
    @ApiOperation("启用/禁用")
    @SaCheckPermission("plan:PlanTunnelRepair:status:change")
    @PutMapping("/status/change/{id}/{status}")
    @Log(title = "巷道修复计划启用/禁用", businessType = BusinessType.GRANT)
    public R<Void> changeStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        planTunnelRepairService.changeStatus(id, status);
        return R.ok();
    }

    /**
     * 获取巷道修复计划列表
     */
    @ApiOperation("获取巷道修复计划分页列表")
//    @SaCheckPermission("plan:PlanTunnelRepair:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<PlanTunnelRepairVo>> page(PlanTunnelRepairReq planMining, PageQuery pageQuery) {
        return R.ok(planTunnelRepairService.selectPageList(planMining, pageQuery));
    }


    /**
     * 获取巷道修复计划列表
     */
    @ApiOperation("获取巷道修复计划列表")
//    @SaCheckPermission("plan:PlanTunnelRepair:list")
    @GetMapping("/list")
    public R<List<PlanTunnelRepairVo>> list(PlanTunnelRepairReq planMining) {
        return R.ok(planTunnelRepairService.selectList(planMining));
    }

    /**
     * 获取巷道修复计划详情
     */
    @ApiOperation("获取巷道修复计划详情")
//    @SaCheckPermission("plan:PlanTunnelRepair:detail")
    @GetMapping("/{id}")
    public R<PlanTunnelRepairVo> detail(@PathVariable("id") String id) {
        return R.ok(planTunnelRepairService.selectDetailById(id));
    }


}
